﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Data.Common;
using SuperMarket.Model;

namespace SuperMarket.DAL
{
    /// <summary>
    /// 管理员查询
    /// </summary>
    public class AdminService
    {
        DBHelper db = new SqlServerDBHelper();

       
        /// <summary>
        /// 使用用户名和密码登录并获取用户信息对象
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public AdminInfo Login(string name, string pass)
        {
            string sql = string.Format(@"select * from AdminInfo 
where AdminName='{0}' and AdminPass='{1}'", name, pass);
            Console.WriteLine(sql);
            DbDataReader dr = db.ExecuteReader(sql);
            AdminInfo admin = null;
            if (dr.Read())//判断是否读取到数据
            {
                admin = new AdminInfo();
                admin.AdminId = Convert.ToInt32(dr["AdminId"]);
                admin.AdminName = dr["AdminName"].ToString(); 
                admin.AdminPass = dr["AdminPass"].ToString();
                admin.AdminRole = Convert.ToInt32(dr["AdminRole"]);
                admin.AdminStatus = Convert.ToInt32(dr["AdminStatus"]);
            }
            dr.Close();
            db.Close();
            return admin;
        }
    }
}
